#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

bool cmp(pair<int,int> a,pair<int,int> b){
    return a.first*b.second<b.first*a.second;
}

void solve(){
    int n;
    cin>>n;
    vector<pair<int,int>> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end(),cmp);
    ll t=0;
    ll cnt=0;
    for(int i=0;i<n;i++){
        cnt+=t*v[i].second;
        t+=2*v[i].first;
    }
    cout<<cnt<<endl;

    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();

    return 0;
}